<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工编号" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入员工编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dimission:add']"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dimission:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dimissionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="离职编号" align="center" prop="did" />
      <el-table-column label="员工编号" align="center" prop="userid" />
      <el-table-column label="员工姓名" align="center" prop="username" />
      <el-table-column label="家庭住址" align="center" prop="home" />
      <el-table-column label="员工部门" align="center" prop="department" />
      <el-table-column label="岗位" align="center" prop="deptdetailid" />
      <el-table-column label="电话" align="center" prop="phone" />

<!--      <el-table-column label="邮箱" align="center" prop="mailbox" />-->

      <el-table-column label="离职原因" align="center" prop="dimission" />

      <el-table-column label="批准" align="center" prop="mailbox" >

      <template slot-scope="scope">
<!--        <el-button @click="drawer = true" type="primary" style="margin-left: 21px;">-->
<!--          操作-->
<!--        </el-button>-->

<!--        <el-drawer-->
<!--          title="我是标题"-->
<!--          :visible.sync="drawer"-->
<!--          :with-header="false">-->
<!--            <span>-->
<!--              <el-table v-loading="loading" :data="wagesList" @selection-change="handleSelectionChange">-->

<!--                <el-table-column label="员工编号" align="center" prop="userid" />-->


<!--              </el-table>-->
<!--            </span>-->
<!--        </el-drawer>-->
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleDelete(scope.row)"
                    v-hasPermi="['system:dimission:remove']"
                  >同意</el-button>

        <el-button
          size="mini"
          type="text"
          @click="handleDelete1(scope.row)"
          v-hasPermi="['system:dimission:remove']"
        >驳回</el-button>

      </template>

      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dimission:edit']"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:dimission:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改离职信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="员工编号" prop="userid">
          <el-input v-model="form.userid" placeholder="请输入员工编号" />
        </el-form-item>
        <el-form-item label="员工姓名" prop="username">

          <el-select v-model="form.username" filterable placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.username"
              :label="item.storeName"
              :value="item.username">
            </el-option>
          </el-select>

<!--          <el-input v-model="form.username" placeholder="请输入员工姓名" />-->
        </el-form-item>
        <el-form-item label="家庭住址" prop="home">
          <el-input v-model="form.home" placeholder="请输入家庭住址" />
        </el-form-item>
        <el-form-item label="员工部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入员工部门" />
        </el-form-item>
        <el-form-item label="岗位" prop="deptdetailid">
          <el-input v-model="form.deptdetailid" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>


        <el-form-item label="离职原因" prop="dimission">
          <el-input v-model="form.dimission" placeholder="请输入离职原因" />
        </el-form-item>

<!--        <el-form-item label="邮箱" prop="mailbox">-->
<!--          <el-input v-model="form.mailbox" placeholder="请输入邮箱" />-->
<!--        </el-form-item>-->


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


<!--    &lt;!&ndash; 添加或修改离职信息管理对话框 &ndash;&gt;-->
<!--    <el-dialog :title="title1" :visible.sync="open1" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form1" :rules="rules1" label-width="80px">-->
<!--        <el-form-item label="员工编号" prop="userid">-->
<!--          <el-input v-model="form.userid" placeholder="请输入员工编号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="员工姓名" prop="username">-->

<!--          <el-select v-model="form.username" filterable placeholder="请选择">-->
<!--            <el-option-->
<!--              v-for="item in options"-->
<!--              :key="item.username"-->
<!--              :label="item.storeName"-->
<!--              :value="item.username">-->
<!--            </el-option>-->
<!--          </el-select>-->

<!--          &lt;!&ndash;          <el-input v-model="form.username" placeholder="请输入员工姓名" />&ndash;&gt;-->
<!--        </el-form-item>-->
<!--        <el-form-item label="家庭住址" prop="home">-->
<!--          <el-input v-model="form.home" placeholder="请输入家庭住址" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="员工部门" prop="department">-->
<!--          <el-input v-model="form.department" placeholder="请输入员工部门" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="岗位" prop="deptdetailid">-->
<!--          <el-input v-model="form.deptdetailid" placeholder="请输入岗位" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="电话" prop="phone">-->
<!--          <el-input v-model="form.phone" placeholder="请输入电话" />-->
<!--        </el-form-item>-->


<!--        <el-form-item label="离职原因" prop="dimission">-->
<!--          <el-input v-model="form.dimission" placeholder="请输入离职原因" />-->
<!--        </el-form-item>-->

<!--        &lt;!&ndash;        <el-form-item label="邮箱" prop="mailbox">&ndash;&gt;-->
<!--        &lt;!&ndash;          <el-input v-model="form.mailbox" placeholder="请输入邮箱" />&ndash;&gt;-->
<!--        &lt;!&ndash;        </el-form-item>&ndash;&gt;-->


<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">批 准</el-button>-->
<!--        <el-button @click="cancel">驳 回</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->



  </div>
</template>

<script>
import {approve, listlzxx, listDimission, getDimission, delDimission, addDimission, updateDimission } from "@/api/system/dimission";

export default {
  name: "Dimission",
  data() {
    return {
      options: [], //存储所以的mingz信息
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 离职信息管理表格数据
      dimissionList: [],
      // 弹出层标题
      title: "",
      title1: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userid: null,
        username: null,
      },
      // 表单参数
      form: {},
      form1: {},
      // 表单校验
      rules: {
        userid: [
          { required: true, message: "员工编号不能为空", trigger: "blur" }
        ],
        username: [
          { required: true, message: "员工姓名不能为空", trigger: "blur" }
        ],
        home: [
          { required: true, message: "家庭住址不能为空", trigger: "blur" }
        ],
        mailbox: [
          { required: true, message: "邮箱不能为空", trigger: "blur" }
        ],
      }

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询离职信息管理列表 */
    getList() {
      this.loading = true;
      listDimission(this.queryParams).then(response => {
        this.dimissionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        did: null,
        userid: null,
        username: null,
        home: null,
        department: null,
        deptdetailid: null,
        phone: null,
        mailbox: null,
        dimission: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.did)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加离职信息管理";

      //调用后端展示所有名字，下拉框展示

      listlzxx().then(aaa =>{
        console.log("结果： ",JSON.stringify(aaa))
        this.options = aaa.data
      })

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const did = row.did || this.ids
      getDimission(did).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改离职信息管理";
      });



      //调用后端展示所有名字，下拉框展示

      listlzxx().then(aaa =>{
        console.log("结果： ",JSON.stringify(aaa))
        this.options = aaa.data
      })

    },
     /** 提交按钮 */
     submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.did != null) {
            updateDimission(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDimission(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dids = row.did || this.ids;
      this.$modal.confirm('是否同意离职信息管理编号为"' + dids + '"的离职申请？').then(function() {
        return delDimission(dids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("已批准");
      }).catch(() => {});
    },

    /** 驳回按钮操作 */
    handleDelete1(row) {
      const dids = row.did || this.ids;
      this.$modal.confirm('是否驳回离职信息管理编号为"' + dids + '"的离职申请？').then(function() {
        return delDimission(dids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("成功驳回");
      }).catch(() => {});
    },


    // /** 批改按钮操作 */
    // approve(row) {
    //   // const dids = row.did || this.ids;
    //   // this.$modal.confirm('是否同意离职信息管理编号为"' + dids + '"的离职申请').then(function() {
    //   //   return delDimission(dids);
    //   // }).then(() => {
    //   //   this.getList();
    //   //   this.$modal.msgSuccess("已批准对离职信息管理编号为\"' + dids + '\"的离职申请");
    //   // }).catch(() => {});
    //   this.reset();
    //   const did = row.did || this.ids
    //   getDimission(did).then(response => {
    //     this.form1 = response.data;
    //     this.open1 = true;
    //     this.title = "批改离职信息";
    //   });
    //
    //   //调用后端展示所有名字，下拉框展示
    //
    //   // listlzxx().then(aaa =>{
    //   //   console.log("结果： ",JSON.stringify(aaa))
    //   //   this.options = aaa.data
    //   // })
    //
    // },

    /** 导出按钮操作 */
    handleExport() {
      this.download('system/dimission/export', {
        ...this.queryParams
      }, `dimission_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
